var HtmlWebpackPlugin = require('html-webpack-plugin');
const folder_list = require('./base-config/webpack.dir-foreach.config.js');
const TransferWebpackPlugin = require('transfer-webpack-plugin');

let path = require('path'),
    appPath = path.resolve(__dirname,'app'),
    distPath = path.resolve(__dirname,'dist');

let exportConfig = {
  entry:{
    main:['./app/index.js']
  },
  output: {
    path: path.resolve(__dirname,'dist'),
    filename:'static/js/[name].js',
    publicPath:""
  },
  plugins: [
    new TransferWebpackPlugin([
      {from: './app/lib',to:'./lib'},
      {from: './app/static',to:'./static'},
      {from: './app/temp',to:'./temp'},
     ])
  ],
  module: {
    loaders: [
      {
        test:/\.(js|jsx)$/,
        loader:'babel',
        exclude:/node_modules/,
        query:{
          presets:['es2015','stage-2']
        }
      },
      {
        // 图片加载器，雷同file-loader，更适合图片，可以将较小的图片转成base64，减少http请求
        // 如下配置，将小于8192byte的图片转成base64码
        test: /\.(png|jpg|gif)$/,
        loader: 'url?limit=8192&name=./static/img/[hash].[ext]',
      },
      { test: /\.ejs$/, loader: 'ejs-loader'},
      { test: /\.html$/, loader: 'html-loader' }
    ]
  },
};


var str = 'commonhtml';
folder_list.forEach(function(item,index,array){
    if(str == item){
      folder_list.splice(index,1);
      generatehtml(folder_list);
    }
});

function generatehtml(obj){
    obj.forEach(function(pagename,index,array){
        const htmlgenerate = new HtmlWebpackPlugin({
            title: '',
            hash: true,
            filename: pagename + '.html',
            template: 'app/pages/' + pagename + '/' + pagename + '.js',
            inject: false
        })
        exportConfig.plugins.push(htmlgenerate);
    });
}



module.exports = exportConfig;
